VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "ClsDosificacion"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit

Public WithEvents orset As ClsRecordset
Attribute orset.VB_VarHelpID = -1

Public Event DataChanged()

Public codigo As String
Public codSucursal As String
Public fecha_dosificacion As String
Public autorizacion As String 'o numero de autorizacion
Public numero_inicial As Long
Public numero_final As Long
Public habilitada As Boolean
Public llave As String
Public tipo As String
Public fecha_limite As String

Private Sub Class_Initialize()
    Set orset = New ClsRecordset
    orset.setCampos dbCampos(dsf)
    orset.setTablas Array(dsf)
End Sub
Private Sub Class_Terminate()
    Set orset = Nothing
End Sub

Public Sub consulta(Optional sucursalCod As String = "", Optional optHabilitada As String = "")
    Dim condiciones As Variant
    If sucursalCod <> "" Then
        condiciones = concatenaVectores(condiciones, Array(dsf_sfa_id & "=" & sucursalCod))
    End If
    If optHabilitada <> "" Then
        condiciones = concatenaVectores(condiciones, Array(dsf_habilitada & "=" & optHabilitada))
    End If
    orset.consulta condiciones, Array(dsf_fecha_dosificacion & " DESC", dsf_id & " ASC")
End Sub
Public Sub consultaDatos(codig As String)
    orset.consulta Array(dsf_id & "='" & codig & "'")
    orset.CierraRec
End Sub
Public Sub consultaXOrden(nroAut As String)
    orset.consulta Array(dsf_autorizacion & "='" & nroAut & "'")
    orset.CierraRec
End Sub
Public Function habilitar() As Boolean
    'no puede habilitar si la dosificacion tiene facturas emitidas
    Dim facturas As ClsFactura
    Set facturas = New ClsFactura
    facturas.consultaCuentaXDosificacion Me.codigo
    If facturas.orset.numRegistros > 0 Then
        If facturas.orset.getDato("cuenta", 0) > 0 Then
            'no se puede habilitar
            habilitar = False
            'y la pone como deshabilitada
            orset.sUpdateGral Array(dsf_habilitada), _
                              Array("0"), _
                              Array(dsf), _
                              Array(dsf_id & "='" & Me.codigo & "'"), False
            Exit Function
        Else
            
        End If
    End If
    Dim tempCodigo As String
    tempCodigo = Me.codigo
    orset.sUpdateGral Array(dsf_habilitada), _
                      Array("0"), _
                      Array(dsf), _
                      Array(dsf_sfa_id & "=" & Me.codSucursal), False
    'y habilita esta dosificacion
    orset.sUpdateGral Array(dsf_habilitada), _
                      Array("1"), _
                      Array(dsf), _
                      Array(dsf_id & "='" & tempCodigo & "'"), False
    habilitar = True
End Function
Private Sub Reload_members()
    With orset
        codigo = .getDato(dsf_id)
        codSucursal = .getDato(dsf_sfa_id)
        fecha_dosificacion = .getDato(dsf_fecha_dosificacion)
        autorizacion = .getDato(dsf_autorizacion)
        numero_inicial = .getDato(dsf_numero_inicial)
        numero_final = .getDato(dsf_numero_final)
        habilitada = .getDato(dsf_habilitada)
        llave = .getDato(dsf_llave)
        tipo = .getDato(dsf_tipo)
        fecha_limite = .getDato(dsf_fecha_limite)
    End With
    RaiseEvent DataChanged
End Sub
Public Sub Nuevo(newSfaId As String, newFechaDosificacion As String, newAutorizacion As String, newNumeroInicial As String, newNumeroFinal As String, newHabilitada As String, newLlave As String, newTipo As String, newFechaLimite As String)
    orset.sInsert Array("", newSfaId, newFechaDosificacion, newAutorizacion, newNumeroInicial, newNumeroFinal, newHabilitada, newLlave, newTipo, newFechaLimite)
End Sub
Public Sub Modificar(codig As String, newSfaId As String, newFechaDosificacion As String, newAutorizacion As String, newNumeroInicial As String, newNumeroFinal As String, newHabilitada As String, newLlave As String, newTipo As String, newFechaLimite As String)
    orset.sUpdate Array(codig, newSfaId, newFechaDosificacion, newAutorizacion, newNumeroInicial, newNumeroFinal, newHabilitada, newLlave, newTipo, newFechaLimite)
End Sub
Public Sub Borrar(codig As String)
    orset.sDelete codig
End Sub
Private Sub orset_DataChanged()
    Reload_members
End Sub
